<!--
 * @Author: 梁卓
 * @Date: 2022-02-11 23:39:53
 * @LastEditTime: 2022-02-13 12:27:18
 * @LastEditors: Please set LastEditors
 * @Description: 荣誉积分echarts展示
 * @FilePath: \dreamUi\src\componets\echarts\HonorScore.vue
-->
<template>
  <div class="honor_page">
    <div style="width: 100%;height: 100%;" ref="honor_echarts"></div>
  </div>
</template>

<script>
import * as echarts from 'echarts';
export default {
  name: 'HonorScore',
  data() {
    return {
      chart: null
    };
  },
  computed: {

  },
  mounted() {
    this.getData()
    window.addEventListener('resize',this.chart)
  },
  destroyed() {
    window.removeEventListener('resize',this.chart);
  },
  methods: {
    getData() {
      this.$ajax.get('/semesterScore/getNum').then(res => {
        const {data} = res.data
        const arrX = []
        const arrY = []
        data.forEach(item => {
          arrX.push(item.date)
          arrY.push(item.count)
        });
        this.myEcharts(arrX, arrY)
      });
    },
    myEcharts(arrX,arrY) {
      this.chart = echarts.init(this.$refs.honor_echarts);
      const size = this.$refs.honor_echarts.offsetWidth;
      //配置图表
      this.chart.setOption({
        title: {
          text: '各个绩点分段的学生人数',
        },
        tooltip: {},
        legend: {
          data: ['人数']
        },
        xAxis: {
          data: arrX
        },
        yAxis: {},
        series: [{
          name: '人数',
          type: 'bar',
          data: arrY
        }]
      });
      this.chart.resize();
    }
  },
};
</script>

<style scoped>
.honor_page{
  width: 100%;
  height: 100%;
}
</style>